package com.zhj.leetcode;

import java.util.Arrays;

/**
 * 力扣 881
 * 救生艇
 * @author zhj
 */
public class Test881 {
    public static void main(String[] args) {
        int[] nums = {3, 5, 3, 4, 1, 2};
        System.out.println(JSTNum(nums, 5));
    }

    private static int JSTNum(int[] nums, int limit) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        Arrays.sort(nums);
        int l = 0;
        int r = nums.length - 1;
        int res = 0;
        while (l <= r) {
            if (nums[l] + nums[r] <= limit) {
                l = l + 1;
            }
            r = r -1;
            res = res + 1;
        }
        return res;
    }
}
